<?php
class LanguagesController extends AppController {

	var $name = 'Languages';
	var $helpers = array('Html', 'Form' );
	var $uses = array('Language', 'Apartment');

	function admin_add() {
		if (empty($this->data)) {
			$this->set('apartments', $this->Apartment->generateList());
			$this->render();
		} else {
			$this->cleanUpFields();
			if ($this->Language->save($this->data)) {
				$this->Session->setFlash('The Language has been saved');
				$this->redirect('/admin/languages/index');
			} else {
				$this->Session->setFlash('Please correct errors below.');
				$this->set('apartments', $this->Language->Apartment->generateList());
			}
		}
	}

	function admin_edit($id = null) {
		if (empty($this->data)) {
			if (!$id) {
				$this->Session->setFlash('Invalid id for Language');
				$this->redirect('/admin/languages/index');
			}
			$this->data = $this->Language->read(null, $id);
			$this->set('apartments', $this->Apartment->generateList());
		} else {
			$this->cleanUpFields();
			if ($this->Language->save($this->data)) {
				$this->Session->setFlash('The Language has been saved');
				$this->redirect('/admin/languages/index');
			} else {
				$this->Session->setFlash('Please correct errors below.');
				$this->set('apartments', $this->Language->Apartment->generateList());
			}
		}
	}

	function admin_index() {
		$this->Language->recursive = 0;
		$this->set('languages', $this->Language->findAll());
	}
}
?>
